package com.zoho.daliansheng.config;


import org.springframework.stereotype.Component;

// crm 模块路径
@Component
public class CRMSqlQuery {

    CRMPathConfig crmPathConfig;

    public CRMSqlQuery(CRMPathConfig crmPathConfig) {
        this.crmPathConfig = crmPathConfig;
    }

    // 发货单模块，通过 erp_id 和 所属公司 查询
    public String getDispatchSqlByErpId(String dlid, String companyName) {
        return "SELECT id,Account_Name,BusinessType,SalesType,ShippingDate,OrderDate,order_number,Salesman,ShippingAddressnew " +
                " FROM " + crmPathConfig.getDispatchModuleName() + " WHERE erp_id = '" + dlid + "'AND KHCompany = '" + companyName + "'";
    }

    // 发货单模块，通过 pk_id 和 所属公司 查询
    public String getDispatchSqlByPKId(String pk_id, String companyName) {
        return "SELECT id FROM " + crmPathConfig.getDispatchModuleName() + " WHERE pk_id = '" + pk_id + "'AND KHCompany = '" + companyName + "'";
    }

    // 发货单明细模块，通过 id 和 所属公司 查询
    public String getDispatchDetailSqlByErpId(String pk_id, String companyName) {
        return "SELECT id FROM " + crmPathConfig.getDispatchDetailModuleName() + " WHERE autoid = '" + pk_id + "'AND KHCompany = '" + companyName + "'";
    }

    // 销售订单模块，通过 ErpNumber 和 所属公司 查询
    public String getSaleOrderSqlByErpNumber(String csocode, String companyName) {
        return "SELECT id FROM " + crmPathConfig.getGetSaleOrderModuleName() + " WHERE ERP_Number = '" + csocode + "'AND KHCompany = '" + companyName + "'";
    }

    // 地址库模块，通过 accountId 查询
    public String getAddressByAccount(String accountId) {
        return "SELECT id,Name,ShippingContactDizhiku,Sheng,Shi,AddressDizhiku,EndAccount,default FROM " + crmPathConfig.getAddressModuleName() + " WHERE AccountName.id = '" + accountId + "'";
    }

    //  收款单 模块，通过 ERP 查询
    public String getAcceptListByERP(String cvouchid,String companyName,String searchWord) {
        return "SELECT id FROM " + crmPathConfig.getAcceptListModuleName() + " WHERE (((ERP = '" + cvouchid  + "') AND AffiliatedCompany = '" + companyName + "') AND order_type = '" + searchWord + "')";
    }

    //  联系人 模块，通过 ErpNumber 和 所属公司 查询
    public String getContactById(String accountId) {
        return "SELECT id,Phone,Last_Name,AccountName_zongbu,Owner,Department,Title,isMajor,Email,work_place  FROM " + crmPathConfig.getContactModuleName() + " WHERE Account_Name.id = '" + accountId + "'" ;
    }
}
